﻿/*
Plugin=CustomPlugin_DynamicFileMenu_AE_Preset
Name1=AE 动态菜单 预设
Command1=CustomPlugin_DynamicFileMenu_AE_Preset
Version=1.0
*/
CustomPlugin_DynamicFileMenu_AE_Preset(){

	; dirMenu2=%WorkFlow%\custom\ae_scripts\PresetAnimation
	dirMenu2:=QZData("%AePresetAnimation%")

	menu_fromfiles("filelist2", "预设", "RunAePreset1", dirMenu2, "*.ffx", 1)

}

RunAePreset1:
{
   curpath := menu_itempath("filelist2", dirMenu2)
	setPath:=StrReplace(curpath,"\", "/")
   setPreset=%dirMenu2%\setPreset.jsx

    FileDelete, %setPreset% ;避免重复删除文件
    FileAppend,  ; 这里需要逗号.
    (
var	myPreset=File("%setPath%")
var activeItem = app.project.activeItem;
if (activeItem instanceof CompItem) {
    var selectedLayers = activeItem.selectedLayers;
    var numSelectedLayers = selectedLayers.length;
    if (numSelectedLayers >= 1) {
        for (var i = 0; i < numSelectedLayers; i += 1) {
          var layer = app.project.activeItem.selectedLayers[0];
          layer.applyPreset(myPreset);
        }
    } else {
        alert("请选择一个或多个图层.", "BoBO提示你");
    }
}
    ), %dirMenu2%\setPreset.jsx,UTF-8

	sleep 50
	WinActivate, ahk_exe AfterFX.exe
	global AeExePath := ini.BOBOPath_Config.AEPath
    RunWait, %AeExePath% -s -r %setPreset%,,Hide
	sleep 50
	FileDelete, %setPreset% ;避免重复删除文件
    return
}
RETURN